import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import 'hm_navigator.dart';

/// 路由适配
abstract class RoutesAdaptor {
  /// 注册路由
  registerRoutes(HMNavigator navigator);

  /// 当前模块所有路由
  /// Tabbar根页面路由不需要设置parentNavigatorKey！！！
  List<RouteBase> allRoutes({GlobalKey<NavigatorState>? navigatorKey}) => [];
}

/// 字符串扩展
extension CHURLConvertible on String {
  /// url地址
  Uri? get urlValue => Uri.parse(this);

  /// query参数
  Map<String, String> get queryParameters =>
      urlValue?.queryParameters ?? <String, String>{};

  /// 拼接queryParameters
  String withQueryParameters(Map<String, String> parameters) {
    final uri = Uri.parse(this);
    final mergedParameters = {...uri.queryParameters, ...parameters};
    final newUri = uri.replace(queryParameters: mergedParameters);
    return newUri.toString();
  }
}
